#!/bin/bash

#for var in ${!SERF*}; do echo ${var}=${!var};done

# ask
serf members -status=alive | while read line ;do
  NEXT_HOST=$(echo $line|cut -d' ' -f 1)
  NEXT_SHORT=${NEXT_HOST%%.*}
  NEXT_ADDR=$(echo $line|cut -d' ' -f 2)
  NEXT_IP=${NEXT_ADDR%%:*}
  echo address=\"/$NEXT_HOST/$NEXT_SHORT/$NEXT_IP\"
  IFS='.' read -a NEXT_IP_ARRAY <<< "$NEXT_IP"
  echo ptr-record=${NEXT_IP_ARRAY[3]}.${NEXT_IP_ARRAY[2]}.${NEXT_IP_ARRAY[1]}.${NEXT_IP_ARRAY[0]}.in-addr.arpa,$NEXT_HOST
done > /etc/dnsmasq.d/0hosts

service dnsmasq restart
